package com.demoo.zjsu;

import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * Created by jshjsh on 2016/8/14.
 */
@Service
public class TestCacheJava implements Tasklet{

    @Cacheable("smartWeb")
    public String message(){
        String s = "";
        for (int i = 0; i < 10; i++) {
            s += i;
        }
        return s;
    }

    @Cacheable(value = "smartWeb",key = "#root.methodName")
    public String message2(){
        String s = "";
        for (int i = 0; i < 11; i++) {
            s += i;
        }
        return s;
    }

    @Cacheable(value = "smartWeb",key = "#root.methodName")
    public String message3(){
        String s = "";
        for (int i = 0; i < 9; i++) {
            s += i;
        }
        return s;
    }

    @CacheEvict("smartWeb")
    public String message4(){
        String s = "";
        for (int i = 0; i < 12; i++) {
            s += i;
        }
        return s;
    }

    @CacheEvict(value = "smartWeb",key = "#s")
    public String message5(){
        String s = "";
        for (int i = 0; i < 13; i++) {
            s += i;
        }
        return s;
    }

    public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {
        System.out.println("运行一次");
        return RepeatStatus.FINISHED;
    }
}
